﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data;
using QuanLyBanHang.DataConnection;
using System.Windows.Forms;

namespace QuanLyBanHang.QuerySQL
{
    class ClassNV
    {
        Connect conn = new Connect();
        //Show
        public DataTable ShowNV()
        {
            DataTable tb = new DataTable(); ;
            try{
                string sql = "select *from NHANVIEN";
                tb = conn.getTable(sql);
            }
            catch (Exception e){
                MessageBox.Show("Lỗi: " + e.Message);
            }
            return tb;
        }
        public DataTable ShowMANV(string manv)
        {
            DataTable tb = new DataTable(); ;
            try
            {
                string sql = "select *from NHANVIEN where MANV like '%"+manv+"%'";
                tb = conn.getTable(sql);
            }
            catch (Exception e)
            {
                MessageBox.Show("Lỗi: " + e.Message);
            }
            return tb;
        }
        public DataTable ShowTNV(string tennv)
        {
            DataTable tb = new DataTable(); ;
            try
            {
                string sql = "select *from NHANVIEN where TENNV like N'%"+tennv+"%'";
                tb = conn.getTable(sql);
            }
            catch (Exception e)
            {
                MessageBox.Show("Lỗi: " + e.Message);
            }
            return tb;
        }
        //them sua xoa
        public void ThemNV(string manv, string tennv,string gioitinh, string dc, string sdt, string ns)
        {
            DateTime dt1 = Convert.ToDateTime(ns);
            try
            {
                string sql = "insert into NHANVIEN values('" + manv + "',N'" + tennv + "','" + gioitinh + "',N'" + dc + "','" + sdt + "','" + string.Format("{0:MM/dd/yyyy}", dt1) + "')";
                conn.ExcuteQuerySql(sql);
                MessageBox.Show("Thêm thành công !!!");
            }
            catch (Exception e)
            {
                MessageBox.Show("Lỗi: " + e.Message);
            }            
        }
        public void SuaNV(string manv, string tennv, string gioitinh, string dc, string sdt, string ns)
        {
            try
            {
                string sql = "update NHANVIEN set TENNV =N'"+tennv+"',GIOITINH ='"+gioitinh+"',DIACHINV =N'"+dc+"',SODT ='"+sdt+"',NGAYSINH ='"+ns+"' where MANV = '"+manv+"' ";
                conn.ExcuteQuerySql(sql);
                MessageBox.Show("Sửa thành công !!!");
            }
            catch (Exception e)
            {
                MessageBox.Show("Lỗi: " + e.Message);
            }
        }
        public void XoaNV(string manv)
        {
            try
            {
                string sql = "delete NHANVIEN where MANV = '" + manv + "'";
                conn.ExcuteQuerySql(sql);
                MessageBox.Show("Xóa thành công !!!");
            }
            catch (Exception e)
            {
                MessageBox.Show("Lỗi: " + e.Message);
            }            
        }
    }
}
